const { mongoose, db } = require('../utils/mongoose')
let schema = mongoose.Schema({
    id:{type:String,required:true},
    title:{type:String,required:true}
})

let Collection = mongoose.model('titles', schema)


//新增
const creteTitle=(data)=>{
    let model = new Collection(data)
    return model.save()
        .then(res => res)
        .catch(err => {
            console.log(err);
            return false;
        })
}
//查询
// .sort({'date':-1})//按插入时间倒序排列
// date:{$gte: sDate, $lte: eDate}
const findTitles=()=>{
    return Collection.find().sort({'id':-1})
        .then(res=>res)
        .catch(err=>{
            console.log(err);
            return false;
        })
}
//删除
let delTitle = (query = {}) => {
    return Collection.deleteOne(query)
        .then(res=>res)
        .catch(err=>{
            console.log(err)
            return false;
        })
}
module.exports={
    creteTitle,
    findTitles,
    delTitle
}